﻿Public Class FormPlan
    Public usr As String
    Dim objLhPgd As New clsLhPgd
    Dim dt As DataTable
    Dim objProdSpec As New clsProdSpec
    Dim httpHelper As New HttpHelper
    Private Sub FormPlan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        initDgv()
    End Sub

    Private Sub initDgv()
        'dt = objLhPgd.getLhPgd()
        dt = objLhPgd.getLHPlan()
        dgvDetails.Font = New Font("UTF-8", 12)
        dgvDetails.AutoGenerateColumns = False
        dgvDetails.DataSource = dt
    End Sub

    Private Sub dgvDetails_SelectionChanged(sender As Object, e As EventArgs) Handles dgvDetails.SelectionChanged
        If dgvDetails.SelectedRows.Count > 0 Then
            Dim dtprodspec As DataTable = objProdSpec.selectByProdSpecId(dgvDetails.SelectedRows(0).Cells("support_model").Value.ToString())
            setLhjChkList(chkListassist_marker, dtprodspec.Rows(0)("lhj_type").ToString(), "5")
            For index = 0 To chkListassist_marker.Items.Count - 1
                If dgvDetails.SelectedRows(0).Cells("Col_lhj").Value.ToString().Contains(chkListassist_marker.Items(index).ToString()) Then
                    chkListassist_marker.Items(index).CheckState = CheckState.Checked
                    chkListassist_marker.Items(index).Enabled = False
                End If
            Next
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If dgvDetails.SelectedRows.Count > 0 Then
            If chkListassist_marker.Items.Count > 0 Then
                Dim chklstChecked As Boolean = False
                For i As Integer = 0 To chkListassist_marker.Items.Count - 1
                    If chkListassist_marker.Items(i).CheckState = CheckState.Checked Then
                        chklstChecked = True
                    End If
                Next
                If chklstChecked = False Then
                    MsgBox("请勾选硫化机")
                    chkListassist_marker.Select()
                    Exit Sub
                End If
                If MsgBox("确认要进行保存吗？", vbYesNo, "提示") = vbYes Then
                    Dim assist_marker As String = String.Empty
                    For i As Integer = 0 To chkListassist_marker.Items.Count - 1
                        If chkListassist_marker.Items(i).CheckState = CheckState.Checked Then
                            assist_marker &= chkListassist_marker.Items(i).Value & ","
                        End If
                    Next
                    If assist_marker.Length > 0 Then
                        assist_marker = assist_marker.Substring(0, assist_marker.Length - 1)
                    End If
                    Dim rtn As Integer = objLhPgd.updateLhj(assist_marker, usr, dgvDetails.SelectedRows(0).Cells("Colid").Value.ToString())
                    If rtn <> -2 Then
                        initDgv()
                        submitApi(dgvDetails.SelectedRows(0).Cells("col_lh_pgd_code").Value.ToString(), assist_marker)
                        MsgBox("保存成功")
                    Else
                        MsgBox("保存失败")
                    End If
                End If
            End If
        End If

    End Sub

    Private Sub submitApi(dispatchingorder As String, equip_id As String)
        Dim params As String = "{""dispatchingorder"":""" & dispatchingorder & """,""equip_id"":""" & equip_id & """,""compid"":""0de02b54-4e55-4dbf-ab89-f785df5f405c""}"
        Dim rtn As String = HttpHelper.HttpPostWebService("updateDispatchOrderEquipmentInfo", params)
    End Sub
End Class